package com.zx.onlineeducation.service.sms.controller;

import com.zx.onlineeducation.common.util.R;
import com.zx.onlineeducation.service.sms.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 短信 前端控制器
 *
 * @author 郑雪
 * @since 2022-01-25
 */
@Api(tags = "短信")
@RestController
@RequestMapping("/sms")
@CrossOrigin // 解决跨域
public class SmsController {

    /**
     * 短信服务接口
     */
    @Autowired
    private SmsService smsService;

    @ApiOperation("发送短信验证码")
    @GetMapping("/send/code/{phone}")
    public R sendCode(
            @ApiParam(value = "接收短信的手机号", required = true)
            @PathVariable(value = "phone") String phone) {
        boolean result = smsService.sendCode(phone);
        return result ? R.ok() : R.error();
    }
}
